package game.tileMap.view.background
{
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	/**
	 * 地图背景
	 * @author AresLee
	 * 
	 */	
	public class MapBackground extends Bitmap
	{
		/**
		 *当前操作的图片数据 
		 */		
		public var currentBMD:BitmapData;
		
		/**
		 *增加宽高必须设置 
		 * @param width
		 * @param height
		 * @param bitmapData
		 * @param pixelSnapping
		 * @param smoothing
		 * 
		 */		
		public function MapBackground(width:Number,height:Number,bitmapData:BitmapData=null,pixelSnapping:String="auto", smoothing:Boolean=false)
		{
			super(bitmapData, pixelSnapping, smoothing);
			
			this.bitmapData = new BitmapData(width,height,true,0);
		}
		
		/**
		 *设置地图的x、y坐标 
		 * @param $x
		 * @param $y
		 * 
		 */		
		public function setPos($x:Number,$y:Number):void
		{
			this.x = $x;
			this.y = $y;
		}
		/**
		 *根据偏移量来取图 
		 * @param $source
		 * @param $offsetX
		 * @param $offsetY
		 * 
		 */		
		public function updateByOffset($offsetX:Number,$offsetY:Number):void
		{
			if(currentBMD == null){
				return;
			}
			var bmd:BitmapData = this.bitmapData;
			bmd.lock();
			bmd.fillRect(new Rectangle(0,0,bmd.width,bmd.height),0x778a5c43);
			bmd.copyPixels(currentBMD,new Rectangle($offsetX,$offsetY,bmd.width,bmd.height),new Point(0,0));
			bmd.unlock();
		}
	
	}
	
}